//
//  CompetionInforCell.m
//  ShangHaiTuJI
//
//  Created by xiaoxiangtuji on 2017/7/29.
//  Copyright © 2017年 xiaoxiangtuji. All rights reserved.
//

#import "CompetionInforCell.h"
#import "MatchListModel.h"

@implementation CompetionInforCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

-(void)setModel:(MatchListModel *)model{
    _model = model;
    UIImageView *bgImageView = [[UIImageView alloc] init];
    if (model.maxImgPath) {
        [bgImageView sd_setImageWithURL:[NSURL URLWithString:model.maxImgPath] placeholderImage:[UIImage imageNamed:@""]];
    }else{
            [bgImageView sd_setImageWithURL:[NSURL URLWithString:model.ImgPath] placeholderImage:[UIImage imageNamed:@""]];
    }

    [self addSubview:bgImageView];
    [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(scaleLeftAndRight(10));
        make.right.equalTo(self.mas_right).offset(scaleLeftAndRight(-10));
        make.top.equalTo(self.mas_top).offset(scaleTopAndBottom(10));
        make.height.mas_equalTo(scaleTopAndBottom(140));
    }];
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.textColor = COLOR_HEX(0x121212);
    titleLabel.text = model.name;
    [self addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(scaleLeftAndRight(10));
        make.right.equalTo(self.mas_right).offset(scaleLeftAndRight(-10));
        make.top.equalTo(bgImageView.mas_bottom).offset(scaleTopAndBottom(10));
        make.height.mas_equalTo(scaleTopAndBottom(20));
    }];
    UILabel *timeLabel = [[UILabel alloc] init];
    timeLabel.font = [UIFont systemFontOfSize:14];
    timeLabel.textColor = COLOR_HEX(0xABABAB);
    timeLabel.text = [self getHour:@"" systemTime:model.submitEndTime];
    [self addSubview:timeLabel];
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(scaleLeftAndRight(10));
        
        make.top.equalTo(titleLabel.mas_bottom).offset(scaleTopAndBottom(10));
        make.height.mas_equalTo(scaleTopAndBottom(20));
    }];
    UILabel *countLabel = [[UILabel alloc] init];
    countLabel.font = [UIFont systemFontOfSize:14];
    countLabel.textColor = COLOR_HEX(0xABABAB);
    NSString *countStr = [NSString stringWithFormat:@"%@%@",@"报名人数:",model.count];
    countLabel.text = countStr;
    
    [self addSubview:countLabel];
    [countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(scaleLeftAndRight(-10));
        make.top.equalTo(titleLabel.mas_bottom).offset(scaleTopAndBottom(10));
        make.height.mas_equalTo(scaleTopAndBottom(20));
        make.left.equalTo(timeLabel.mas_right);
        make.width.equalTo(timeLabel.mas_width);
    }];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    if ([model.type integerValue] == 1) {
        [button setTitle:@"线下" forState:0];
        button.titleLabel.font = [UIFont systemFontOfSize:14];
        button.layer.borderWidth = 0.5;
        button.layer.borderColor = [UIColor greenColor].CGColor;
        [button setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
    }else{
        [button setTitle:@"线上" forState:0];
        button.titleLabel.font = [UIFont systemFontOfSize:14];
        button.layer.borderWidth = 0.5;
        button.layer.borderColor = COLOR_HEX(0xF27112).CGColor;
        [button setTitleColor:COLOR_HEX(0xF27112) forState:UIControlStateNormal];
    }

    [self addSubview:button];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(scaleLeftAndRight(10));

        make.top.equalTo(timeLabel.mas_bottom).offset(scaleTopAndBottom(10));
        make.height.mas_equalTo(scaleTopAndBottom(20));
        make.width.mas_equalTo(scaleLeftAndRight(50));
    }];
    

}
/**
 根据时间戳获取到时间差
 
 */
- (NSString* )getHour:(NSString *)takeCarTime systemTime:(NSString *)systemTime

{
    
    //  时区相差8个小时 加上这个时区即是北京时间
    
    NSTimeZone *timeZone = [NSTimeZone systemTimeZone];
    
    NSInteger delta = [timeZone secondsFromGMT];
    
    NSDate *DRstartDate = [NSDate date];
    NSDate *DRendDate = [[NSDate alloc] initWithTimeIntervalSince1970:[systemTime doubleValue]/1000 + delta];
    NSLog(@"开始时间%@",DRstartDate);
    NSLog(@"结束时间%@",DRendDate);
    // 日历对象 （方便比较两个日期之间的差距）
    
    NSTimeInterval interTime = [DRendDate timeIntervalSinceNow];
    //计算天数、时、分、秒
    
    int days = ((int)interTime)/(3600*24);
    
    int hours = ((int)interTime)%(3600*24)/3600;
    
    int minutes = ((int)interTime)%(3600*24)%3600/60;
    
    NSString *dateContent = [[NSString alloc] initWithFormat:@"截止倒计时:%i天%i时%i分",days,hours,minutes];
    NSLog(@"嘎嘎嘎嘎%@",dateContent);
    return dateContent;
    
}




- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
